import o from 'node:fs/promises';
import n from 'node:path';
import { pipeline } from 'node:stream/promises';
import c from 'node:zlib';
import { createReadStream, createWriteStream } from 'node:fs';
import { logger } from './logger.js';
import { hasProperties } from '../cli/utils/utils.js';
import { createHash } from 'node:crypto';

class t{static DATA_DIR=n.join(process.cwd(),".robo","data");async clear(){try{return await o.rm(t.DATA_DIR,{recursive:!0,force:!0}),await o.mkdir(t.DATA_DIR,{recursive:!0}),!0}catch{return !1}}async delete(e){try{const r=n.join(t.DATA_DIR,this._getSafeKey(e));return await o.unlink(r),!0}catch(r){return hasProperties(r,["code"])&&r.code!=="ENOENT"&&logger.warn(`Failed to delete key "${e}" from Flashcore file adapter.`,r),!1}}async get(e){try{const r=n.join(t.DATA_DIR,this._getSafeKey(e)),i=c.createGunzip();await pipeline(createReadStream(r),i);const a=i.read();return a?JSON.parse(a.toString()):void 0}catch{return}}async has(e){return !!await this.get(e)}async init(){try{await o.mkdir(t.DATA_DIR,{recursive:!0});}catch(e){logger.error("Failed to create data directory for Flashcore file adapter.",e);}}async set(e,r){try{const i=n.join(t.DATA_DIR,this._getSafeKey(e)),a=c.createGzip();return a.write(JSON.stringify(r)),a.end(),await pipeline(a,createWriteStream(i)),!0}catch{return !1}}_getSafeKey(e){return createHash("sha256").update(e.toString()).digest("hex")}}

export { t as FlashcoreFileAdapter };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=flashcore-fs.js.map